package com.tbs.easyhomemoneyserver.dao.providers

import cn.hutool.core.util.StrUtil
import com.tbs.easyhomemoneyserver.form.BaseUserSearchForm

class SystemUserDaoProvider {


    fun conditionFindSystemUser(baseUserSearchForm: BaseUserSearchForm): String {
//        select *
//                from easy_home_money . sys_user
//                where
//        #     id = #{}
//        name like 'test%'
//        #   and phone like '#{}%'
//        # and sex = 1
        val stringBuilder = StringBuilder("select * from easy_home_money . sys_user where 1=1 ")
        baseUserSearchForm.id?.let { stringBuilder.append("and id = '").append(it.toString()).append("'") }
        baseUserSearchForm.sex?.let { stringBuilder.append("and sex = '").append(it.toString()).append("'") }
        if (!StrUtil.isBlank(baseUserSearchForm.name)) {
            stringBuilder.append("and name like '").append(baseUserSearchForm.name).append("%'")
        }
        if (!StrUtil.isBlank(baseUserSearchForm.phone)) {
            stringBuilder.append(" and phone like '").append(baseUserSearchForm.phone).append("%'")
        }


        return stringBuilder.toString()

    }
}